package com.zhou.jiancai.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.widget.ListView;

import com.zhou.jiancai.R;
import com.zhou.jiancai.adapter.VideoListAdapter;
import com.zhou.jiancai.application.MyApplication;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;



/**
 * Created by Administrator on 2017/5/19.
 */

/**
 * Created by Nathen
 * On 2016/02/06 19:12
 */
public class JCListActivity extends AppCompatActivity {
    ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //在application里注册在这里获取
        Context context = getApplicationContext();
        MyApplication myApplication=new MyApplication(getApplicationContext());
        myApplication.initImageLoader(context);
        setContentView(R.layout.activity_list);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setDisplayShowTitleEnabled(true);
        getSupportActionBar().setDisplayUseLogoEnabled(false);



     ;
       String result= analysisUrl("http://www.ri004.com");
        System.out.println(result);

         listView = (ListView) findViewById(R.id.listView);
        listView.setAdapter(new VideoListAdapter(this));


    }
    public static String analysisUrl(String url){
        HttpURLConnection httpConnection = null;
        String output = "";
        try {
            URL targetUrl = new URL(url);
            httpConnection = (HttpURLConnection) targetUrl.openConnection();
            httpConnection.setDoOutput(true);
            httpConnection.setRequestMethod("GET");
            httpConnection.setRequestProperty("Content-Type",
                    "application/json");
            InputStreamReader isr = new InputStreamReader(httpConnection
                    .getInputStream(),"utf-8");
            BufferedReader responseBuffer = new BufferedReader(isr);
            output = responseBuffer.readLine();

        } catch (Exception e) {

        } finally {
            httpConnection.disconnect();
        }
        return output;
    }


    @Override
    protected void onPause() {
        super.onPause();
        JCVideoPlayer.releaseAllVideos();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

}


